Skip to content

fix beeai agent#7

Merged
akihikokuroda merged 1 commit intoAI4quantum:mainfrom
akihikokuroda:beeai
Nov 4, 2025
Merged

fix beeai agent#7
akihikokuroda merged 1 commit intoAI4quantum:mainfrom
akihikokuroda:beeai

Conversation

@akihikokuroda
Copy link
Member

Fix beeai agent issues

Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
def no_result_customizer(config: PromptTemplateInput[Any]) -> PromptTemplateInput[Any]:
"""no_result_customizer"""
new_config = config.model_copy()
config.template += """\nPlease reformat your input."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is setting config.template intentional? I don't really understand the logic since we are returning new_config for everything

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bob says

Code Explanation: Lines 217-219 of beeai_agent.go

Context

This code is Python code embedded within a Go string (part of a larger Python script template starting at line 142). The Go code generates and executes this Python script to interact with the BeeAI framework.

The Specific Code (lines 218-219):

def tool_no_result_error_template_func(template: PromptTemplateInput[Any]) -> PromptTemplateInput[Any]:
    return template.fork(customizer=no_result_customizer)

Purpose and Functionality

This function creates a template customization function for handling tool execution errors when a tool returns no result. It's used by the BeeAI agent framework to customize error messages shown to the LLM when a tool fails to produce output.

Key Components

  1. Function Signature:

    • Takes a PromptTemplateInput[Any] template object
    • Returns a modified PromptTemplateInput[Any] template
  2. template.fork(customizer=no_result_customizer):

    • Creates a forked/copied version of the template
    • Applies the no_result_customizer function (defined at lines 182-186)
    • The customizer appends "\nPlease reformat your input." to the template
  3. Integration:

    • This function is registered in the agent's templates dictionary (line 303)
    • Used when a tool executes but returns no result
    • Helps the agent recover from tool execution failures by prompting for reformatted input

Important Patterns

  1. Template Forking Pattern: Uses the .fork() method to create a modified copy without mutating the original template
  2. Customizer Pattern: Separates the customization logic (no_result_customizer) from the template function, promoting reusability
  3. Error Recovery: Part of a broader error handling strategy that includes multiple template customizers for different error scenarios (no result, tool not found, etc.)

Related Code

  • no_result_customizer (lines 182-186): The actual customization logic
  • tool_not_found_error_template_func (lines 221-222): Similar pattern for different error type
  • Templates dictionary (lines 299-305): Where this function is registered and used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make sense?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you ask bob to explain line 182-185, specifically the no_result_customizer? That is the portion I'm a bit confused on, because if you see everything around it we are returning new_config. It seems like setting config.template to me is a bug beacsue we don't really od anything with it, nor do we return it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Templates dictionary (lines 299-305): Where this function is registered and used

The templates are passed to the toolCallingAgent at line 310. It seems to be used by the agent.

@akihikokuroda akihikokuroda merged commit b28e78e into AI4quantum:main Nov 4, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants